package com.jyniubi.core.controller.api;


import com.jyniubi.base.result.R;
import com.jyniubi.core.pojo.entity.Lend;
import com.jyniubi.core.service.LendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author jyzhang
 * @since 2024-04-27
 */
@Api(tags = "标的模块")
@RestController
@RequestMapping("/api/core/lend")
public class ApiLendController {

    @Resource
    private LendService lendService;

    @ApiOperation("计算投资收益")
    @GetMapping("/interestCount/{id}")
    public R getInterestCount(BigDecimal investAmount, @PathVariable("id")String id){
        if (investAmount==null){
            investAmount = BigDecimal.ZERO;
        }
        BigDecimal interestCount = lendService.getInterestCount(investAmount,id);
        return R.ok().data("interestCount",interestCount);
    }

    @ApiOperation("标的列表")
    @GetMapping
    public R lendList(){
        List<Lend> lendList = lendService.getLendList();
        return R.ok().data("items",lendList);
    }

    @ApiOperation("查询标的详情")
    @GetMapping("/{id}")
    public R getLendDetail(@PathVariable("id") String id){
        Map<String,Object> map = lendService.getLendDetail(id);
        return R.ok().data("items",map);
    }
}

